home *** CD-ROM | disk | FTP | other *** search
- {******************************************************************}
- { }
- { Mancala }
- { Turbo Pascal for Windows }
- { Copyright (c) 1991 by Swan Software. All rights reserved. }
- { }
- {******************************************************************}
-
- { ueval.pas -- Move evaluator for Mancala }
-
- unit UEval;
-
- interface
-
- uses UGlobals;
-
- function BoardValue(var Position: BoardRec; Level: Integer): Integer;
-
-
- implementation
-
-
- {- Return evaluation for this game board position. }
-
- function BoardValue(var Position: BoardRec; Level: Integer): Integer;
- var
- I, Score: Integer;
- begin
- with Position do
- begin
-
- {- Return maximum score for win or lowest score for loss. Return
- slightly higher scores for shallower levels to encourage the computer
- to win as early as possible. }
-
- if Gameboard[CompKalah] >= PebblesDiv2 then
- begin
- Win := true;
- WinningSide := computer;
- BoardValue := 255 - Level;
- end else if Gameboard[HumanKalah] >= PebblesDiv2 then
- begin
- Win := true;
- WinningSide := human;
- BoardValue := Level - 255;
- end else
- begin
- Win := false;
-
- {- Initial score is two times the difference between the computer
- and human kalahs }
-
- Score := 2 * (Gameboard[CompKalah] - Gameboard[HumanKalah]);
-
- {- Subtract one point for each human pebble and add one point for
- each computer pebble }
-
- for I := HumanFirstCup to HumanLastCup do
- Score := Score - Gameboard[I];
- for I := CompFirstCup to CompLastCup do
- Score := Score + Gameboard[I];
- Boardvalue := Score; { Assign function result }
- end;
- end;
- end;
-
-
- end.
-
-
- { ----------------------------------------------------------------
- Copyright (c) 1991 by Swan Software. All rights reserved.
- Revision 1.00 Date: 8/21/1991
- ---------------------------------------------------------------- }
-